package com.puhui.education.activity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewStub;
import android.widget.Button;
import android.widget.TextView;

import com.puhui.education.R;
import com.puhui.education.activity.base.BaseAcy;
import com.puhui.education.util.CleanCacheUtil;
import com.puhui.education.util.ToastUtil;
import com.puhui.education.view.TextViewPlus;

import java.math.BigDecimal;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/6/14.
 */
public class SettingsAcy extends BaseAcy {


    @Bind(R.id.vsb_clearCash_settingsAcy)
    ViewStub vsb_clearCash;
    @Bind(R.id.vsb_feedBack_settingsAcy)
    ViewStub vsb_feedBack;
    @Bind(R.id.vsb_about_settingsAcy)
    ViewStub vsb_about;
    @Bind(R.id.bt_exitLogin_settingAcy)
    Button bt_exitLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.acy_settings);
        ButterKnife.bind(this, this);
        initData();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }

    @OnClick(R.id.bt_exitLogin_settingAcy)
    public void onExitLoginClick() {
        CleanCacheUtil.cleanCache(SettingsAcy.this.getCacheDir());
        CleanCacheUtil.size = 0;
        CleanCacheUtil.getCacheSize(SettingsAcy.this.getCacheDir());
        ToastUtil.showBottomToast(CleanCacheUtil.size);
//    if(CleanCacheUtil.size%1024>=1024){
//        tv_rightTab.setText( new BigDecimal((float)CleanCacheUtil.size/1024f/1024f+"").setScale(0, BigDecimal.ROUND_HALF_UP)+"M");
//    }else{
//        tv_rightTab.setText( new BigDecimal((float)CleanCacheUtil.size/1024f+"").setScale(0, BigDecimal.ROUND_HALF_UP)+"KB");
//    }
    }

    @Override
    protected void initData() {
        super.initData();
        initViewStub();

    }

    private void initViewStub() {
        View v_clearCash = vsb_clearCash.inflate();
        v_clearCash.setBackgroundColor(getResources().getColor(R.color.white));
        TextViewPlus tvp_clearCash = (TextViewPlus) v_clearCash.findViewById(R.id.tvp_title_rvItem);
        tvp_clearCash.setText("清除内存");
        TextView tv_rightTab = (TextView) v_clearCash.findViewById(R.id.tv_rightTab_rvItem);
        CleanCacheUtil.size = 0;
        CleanCacheUtil.getCacheSize(SettingsAcy.this.getCacheDir());
        if (CleanCacheUtil.size % 1024 >= 1024) {
            tv_rightTab.setText(new BigDecimal((float) CleanCacheUtil.size / 1024f / 1024f + "").setScale(0, BigDecimal.ROUND_HALF_UP) + "M");
        } else {
            tv_rightTab.setText(new BigDecimal((float) CleanCacheUtil.size / 1024f + "").setScale(0, BigDecimal.ROUND_HALF_UP) + "KB");
        }

        View v_feedBack = vsb_feedBack.inflate();
        v_feedBack.setBackgroundColor(getResources().getColor(R.color.white));
        TextViewPlus tvp_feedBack = (TextViewPlus) v_feedBack.findViewById(R.id.tvp_title_rvItem);
        tvp_feedBack.setText("意见反馈");

        View v_about = vsb_about.inflate();
        v_about.setBackgroundColor(getResources().getColor(R.color.white));
        TextViewPlus tvp_about = (TextViewPlus) v_about.findViewById(R.id.tvp_title_rvItem);
        tvp_about.setText("关于普惠");
        v_clearCash.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.showBottomToast("12345");
            }
        });
    }
}
